// TabControlPeer.cpp : implementation file
//

#include "stdafx.h"
#include "AWT.h"
#include "TabControlPeer.h"
#include "TabControl.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// TabControlPeer

TabControlPeer::TabControlPeer(AWTComponent* comp)
{
	m_comp = comp;
}

TabControlPeer::~TabControlPeer()
{
}


BEGIN_MESSAGE_MAP(TabControlPeer, CTabCtrl)
	//{{AFX_MSG_MAP(TabControlPeer)
	ON_NOTIFY_REFLECT(TCN_SELCHANGE, OnSelchange)
	ON_WM_SIZE()
	ON_WM_ERASEBKGND()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// TabControlPeer message handlers

void TabControlPeer::OnSelchange(NMHDR* pNMHDR, LRESULT* pResult) 
{
	int nTab = GetCurSel();
	
	TabControl* tc = (TabControl*)m_comp;
	tc->setActivePanel(nTab);
	
	*pResult = 0;
}

void TabControlPeer::OnSize(UINT nType, int cx, int cy) 
{
	CTabCtrl::OnSize(nType, cx, cy);
	
	TabControl* tc = (TabControl*)m_comp;
	tc->peerResized();
}

BOOL TabControlPeer::OnEraseBkgnd(CDC* pDC) 
{
	CRect rc;
	GetClientRect(&rc);
	AdjustRect(FALSE, &rc);
	pDC->ExcludeClipRect(&rc);
	
	return CTabCtrl::OnEraseBkgnd(pDC);
}
